export function treeToList(tree, result = [], level = 0) {
  tree.forEach(node => {
    let { children,...obj } = node;
    obj.level = level;
    result.push(obj);
    if (children && children.length) {
      treeToList(children, result, level + 1);
    }
  });
  return result;
}

/**
 * @param {string} path
 * @returns {Boolean}
 */
export function isExternal(path) {
  return /^(https?:|mailto:|tel:)/.test(path)
}

/**
 * 获取2个日期之间的日期列表
 * @param start dayjs对象
 * @param end dayjs对象
 * @returns {*[]}
 */
export function getDatesBetween(start, end) {
  let dates = [];
  let current = end;
  while (current.isAfter(start) || current.isSame(start)) {
    dates.push(current.format('YYYY-MM-DD'));
    current = current.subtract(1, 'day');
  }
  return dates;
}